package com.lams.util;

import java.util.List;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
/**
 * 返回结果包装类
 * 
 * @author Hejunwei
 * 
 */
public class ResultEntity {
	
	private boolean success;
	
	private int totalCount;
	
	private int start;
	
	private int limit;
	
	private String message;
	
	private List data;
	
	public ResultEntity(){}
	public ResultEntity(List data,int totalCount,int start,int limit,String message,boolean success){
		this.data = data;
		this.totalCount = totalCount;
		this.start = start;
		this.limit = limit;
		this.message = message;
		this.success = success;
	}
	public ResultEntity(List data,int totalCount){
		this.data = data;
		this.totalCount = totalCount;
	}
	public ResultEntity(String message,boolean success){
		this.message = message;
		this.success = success;
	}
	public ResultEntity(List data,int totalCount,String message,boolean success){
		this.data = data;
		this.totalCount = totalCount;
		this.message = message;
		this.success = success;
	}
	/**
	 * 结果状态 true OR false
	 */
	public boolean isSuccess() {
		return success;
	}
	/**
	 * 结果状态 true OR false
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}
	/**
	 * 分页查询时用到 总记录数
	 */
	public int getTotalCount() {
		return totalCount;
	}
	/**
	 * 分页查询时用到 总记录数
	 */
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	/**
	 * 分页查询时用到 开始记录数
	 */
	public int getStart() {
		return start;
	}
	/**
	 * 分页查询时用到 开始记录数
	 */
	public void setStart(int start) {
		this.start = start;
	}
	/**
	 * 分页查询时用到 单页记录数
	 */
	public int getLimit() {
		return limit;
	}
	/**
	 * 分页查询时用到 单页记录数
	 */
	public void setLimit(int limit) {
		this.limit = limit;
	}
	/**
	 * 结果描述信息
	 */
	public String getMessage() {
		return message;
	}
	/**
	 * 结果描述信息
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	/**
	 * 结果集 JSON数组
	 */
	public List getData() {
		return data;
	}
	/**
	 * 结果集JSON数组
	 */
	public void setData(List data) {
		this.data = data;
	}
	public static String decode(ResultEntity result){
		JsonConfig config = new JsonConfig();
		config.setIgnoreDefaultExcludes(false);
		config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
		JSONObject json = JSONObject.fromObject(result,config);
		return json.toString();
	}
}
